/*
请假处理
*/
// import test from './test.tsx';
import {
  DatePicker,
  Descriptions,
  Input,
  Table,
  Upload,
  Button,
  Popover,
  Drawer,
} from 'antd';
import ReactDOM from 'react-dom';
import { Link } from 'react-router-dom';
// import request from '@/http';
import React from 'react';
import { Form } from 'antd';
// import React, { useState } from 'react';
import request from '@/http';
import { Select } from 'antd';
import { useState } from 'react';
const { Option } = Select;
const { RangePicker } = DatePicker;
const columns = [
  {
    title: '操作人',
    dataIndex: 'person',
    key: 'person',
  },
  {
    title: '操作事项',
    dataIndex: 'operation',
    key: 'operation',
  },
  {
    title: '操作时间',
    dataIndex: 'operation_time',
    key: 'operation_time',
  },
  {
    title: '说明',
    dataIndex: 'explain',
    key: 'explain',
  },
];
const leaveEdit = (prop: any) => {
  // 得到上个页面传参
  const [formObject] = Form.useForm();
  let student_id;
  let id;
  if (prop.location && prop.location.state) {
    student_id = prop.location.state.student_id;
    id = prop.location.state.id;
  }

  const [data, setData] = React.useState({
    id: '',
    key: 1,
    studentName: '',
    studentNo: '',
    studentIdCard: '', //s身份证
    studentSex: '',
    studentEmail: '',
    studentTell: '',
    studentLogo: '',
    collegeName: '',
    majorName: '',
    gradeName: '',
    className: '',
    teacherName: '',
    teacherTell: '',
    vacationBeginDate: '',
    vacationEndDate: '',
    vacationExplain: '',
    vacationReason: '',
    src: '',
  });
  const loadData = async () => {
    //查询用户基本信息
    const result: any = await request.post('/ask_for_leave/a_t_s/ask/all12', {
      id: id,
    });
    if (result.success) {
      setData(result.data);
    }
    const result2: any = await request.post('/ask_for_leave/a_t_s/ask/commit', {
      id: id,
    });
    if (result2.success) {
      setData(result.data);
    }
  };

  // 请假通过
  const option = async () => {
    const result: any = await request.post(
      '/ask_for_leave/teach/teacher/ask/all11',
      { id: id, student: student_id },
    );
    if (result.success) {
      setData(result.data);
      // console.log('通过');
    }
  };
  // 请假不通过
  const optionOn = async () => {
    const result: any = await request.post(
      '/ask_for_leave/teach/teacher/ask/all1122',
      {
        id: id,
        student: student_id,
        // reason
      },
    );
    if (result.success) {
      const newData = result.data.map((d, index) => {
        return {
          id: d.id,
          key: `k_${index}`,
          course_outtime: d.courseOuttime,
          course_name: d.courseName,
          teacher_name1: d.sxteacher.sxteacherName,
          course_classroom: d.courseClassroom,
          teacher_name2: d.zrteacher,
          date: d.courseCreateTime,
          course_intime: d.courseInttime,
          course_note: d.courseNote,
          course_id: d.courseId,
        };
      });
      // console.log('不通过');
    }
  };
  // 操作记录
  const [data1, setData1] = React.useState();
  const options = async () => {
    const result: any = await request.post('/ask_for_leave/a_t_s/ask/commit', {
      id: id,
      student: student_id,
      // reason
    });
    if (result.success) {
      const newData = result.data.map((d, index) => {
        return {
          person: d.name,
          operation: d.operationMatter,
          operation_time: d.approvalAdoptDate,
          explain: d.approvalInstruction,
        };
      });
      setData1(newData);
    }
  };
  var mountNode = document.getElementById('container');

  // 预加载
  React.useEffect(() => {
    loadData();
    options();
  }, []);

  // 弹窗
  const [visible, setVisible] = useState(false);

  const showDrawer = () => {
    setVisible(true);
  };
  const onClose = () => {
    setVisible(false);
  };

  return (
    <div>
      <Descriptions title="请假详情">
        <Descriptions.Item label="姓名">{data.studentName}</Descriptions.Item>
        <Descriptions.Item label="学号">{data.studentNo}</Descriptions.Item>
        <Descriptions.Item label="身份证号">
          {data.studentIdCard}
        </Descriptions.Item>
        <Descriptions.Item label="性别">
          {data.studentSex === '1' ? '男' : '女'}
        </Descriptions.Item>
        <Descriptions.Item label="邮箱地址">
          {data.studentEmail}
        </Descriptions.Item>
        <Descriptions.Item label="手机号码">
          {data.studentTell}
        </Descriptions.Item>
        <Descriptions.Item label="院系">{data.collegeName}</Descriptions.Item>
        <Descriptions.Item label="专业">{data.majorName}</Descriptions.Item>
        <Descriptions.Item label="年级">{data.gradeName}</Descriptions.Item>

        <Descriptions.Item label="班级">{data.className}</Descriptions.Item>
        <Descriptions.Item label="班主任">{data.teacherName}</Descriptions.Item>
        <Descriptions.Item label="班主任电话">
          {data.teacherTell}
        </Descriptions.Item>
        <Descriptions.Item label="请假开始日期">
          {data.vacationBeginDate}
        </Descriptions.Item>
        <Descriptions.Item label="请假结束日期">
          {data.vacationEndDate}
        </Descriptions.Item>
        <Descriptions.Item label="主题">
          {data.vacationExplain}
        </Descriptions.Item>
        <Descriptions.Item label="请假原因">
          {data.vacationReason}
        </Descriptions.Item>
      </Descriptions>

      <Form form={formObject}>
        <Form.Item label="上传附件" name="enclosure">
          <Upload></Upload>
        </Form.Item>
      </Form>
      <Table columns={columns} dataSource={data1}></Table>
      <Link to="/Teacher/Leave/index">
        <Button onClick={option}>审批通过</Button>
      </Link>
      {/* <Popover
        content={<a onClick={hide}>Close</a>}
        title="Title"
        trigger="click"
        visible={state.visible}
        onVisibleChange={handleVisibleChange}
      > */}
      <Link to="/Teacher/Leave/index">
        <Button type="link" onClick={optionOn}>
          不通过
        </Button>
      </Link>
      {/* <Drawer
        title="不通过原因"
        placement="bottom"
        closable={false}
        onClose={onClose}
        visible={visible}
      >
        <Form>
          <Input></Input>
          <Button onClick={optionOn}>提交</Button>
        </Form>
      </Drawer> */}
      {/* </Popover> */}
      <Link to="/Teacher/Leave/index">
        <Button>返回</Button>
      </Link>
    </div>
  );
};

export default leaveEdit;
